//
//  LRMainMenuNode.m
//  lineRunner_cocos2d
//
//  Created by chen jingsen on 13-1-16.
//  Copyright 2013年 __MyCompanyName__. All rights reserved.
//

#import "LRMainMenuNode.h"


@implementation LRMainMenuNode
+ (id)scene
{
    CCScene *scene = [CCScene node];
    CCLayer *layer = [LRMainMenuNode node];
    [scene addChild:layer];
    return scene;
}

- (id)init
{
    if (self = [super init]) {
        [self LR_initBackground];
        [self LR_initBackgroundLine];
        [self addTitleSprite];
        [self addMenu];
        [self addMoreButton];
        CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self);
    }
    return self;
}

- (void)LR_initBackground
{
    LRParallaxBackground *parallaxbackground = [LRParallaxBackground node];
    [self addChild:parallaxbackground];
}

- (void)LR_initBackgroundLine
{
    CGSize screenSize = [[CCDirector sharedDirector] winSize];
    
    LRMoveLineBackground *lineBackground = [LRMoveLineBackground node];
    //    lineBackground.anchorPoint = CGPointMake(0, 0);
    lineBackground.position = CGPointMake(0, screenSize.height*0.33);
    [self addChild:lineBackground];
}

- (void)addTitleSprite
{
    CGSize screenSize = [[CCDirector sharedDirector] winSize];
    CCSprite *titleSprite = [CCSprite spriteWithFile:@"lr_logo.png"];
    titleSprite.position = CGPointMake(screenSize.width*0.5, screenSize.height - titleSprite.textureRect.size.height*1.5);
    [self addChild:titleSprite];
}

- (void)addMenu
{
    CGSize screenSize = [[CCDirector sharedDirector] winSize];
    NSLog(@"size: %@",NSStringFromCGSize(screenSize));
    LRMainMenuLayer *menulayer = [LRMainMenuLayer node];
    [menulayer setPosition:CGPointMake(screenSize.width*0.5, screenSize.height*0.5)];
    [self addChild:menulayer];
}
- (void)addMoreButton
{
    CGSize screenSize = [[CCDirector sharedDirector] winSize];
    
    CCSprite *moreSprite = [CCSprite spriteWithFile:@"lr_but_moregames.png"];
    moreSprite.position = CGPointMake(screenSize.width - moreSprite.textureRect.size.width*0.5,moreSprite.textureRect.size.height*0.5);
    CCRotateBy* rotateBy =[CCRotateBy actionWithDuration:2.0 angle:360];
    CCRepeatForever *repeatAction = [CCRepeatForever actionWithAction:rotateBy];
    [moreSprite runAction:repeatAction];
    [self addChild:moreSprite];
}
- (void)dealloc
{
    CCLOG(@"%@ : %@", NSStringFromSelector(_cmd), self);
    [super dealloc];
}
@end
